package com.guyaning.deyson_core.core.ui.recycler;

import com.chad.library.adapter.base.entity.MultiItemEntity;

import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;
import java.util.LinkedHashMap;

/**
 * Created by Administrator on 2018/6/5.
 */

public class MultipleItemBean implements MultiItemEntity {

    private final ReferenceQueue<LinkedHashMap<Object,Object>>  ITEM_QUENE = new ReferenceQueue<>();

    private final LinkedHashMap<Object,Object>  MULTIPLE_FIELDS = new LinkedHashMap<>();

    private final SoftReference<LinkedHashMap<Object,Object>>  FIELDS_REFERENCE = new SoftReference<>(MULTIPLE_FIELDS,ITEM_QUENE);

    public MultipleItemBean(LinkedHashMap<Object,Object> fields) {
        FIELDS_REFERENCE.get().putAll(fields);
    }

    public static MultipleItemBeanBuilder builder(){
        return new MultipleItemBeanBuilder();
    }

    @Override
    public int getItemType() {

        return (int) FIELDS_REFERENCE.get().get(MultipleFields.ITEM_TYPE);
    }

    @SuppressWarnings("unchecked")
    public final <T> T getFiled(Object key){
        return (T) FIELDS_REFERENCE.get().get(key);
    }

    public final LinkedHashMap<?,?>  getFileds(Object key){
        return FIELDS_REFERENCE.get();
    }

    public final MultipleItemBean  setField(Object key,Object value){
        FIELDS_REFERENCE.get().put(key,value);
        return this;
    }

}
